package com.nxy.test.socket;

import java.io.*;
import java.net.Socket;

/**
 * Created by snailnan on 2017/2/20.
 */
public class HttpSocket {
    public static void main(String[] args) throws IOException {
        Socket client = new Socket("visitor.fanxing.kugou.com",80);
        OutputStream o = client.getOutputStream();
        PrintStream ps = new PrintStream(o);
        BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
        StringBuilder request = new StringBuilder();

        request.append("GET /VServices/GamesService.GamesService.getList/1032413-0/ HTTP/1.1/r/n");
        request.append("Host: visitor.fanxing.kugou.com/r/n");
        request.append("Cache-Control: no-cache/r/n");
        o.write(request.toString().getBytes());
        client.shutdownOutput();

        boolean flag = true;
        StringBuilder response = new StringBuilder();
        String str;
        while (flag){
            str = reader.readLine();
            if (str != null && !"".equals(str)){
                response.append(str);
            }else{
                flag = false;
            }
        }
        reader.close();
        ps.close();
        System.out.println(response);
    }
}
